package data;

import java.sql.PreparedStatement;
import java.sql.SQLException;

import android.app.Activity;

/**
 * This account removes a user
 * 
 * @author Stephen
 * 
 */

public class UserRemove extends DBBooleanTask<Account> {
	/**
	 * Creates a UserRemove task
	 * 
	 * @param activity
	 *            - the activity to show the task bar
	 * @param account
	 *            - the account to remove
	 * @throws DBInterfaceError
	 *             - the error to throw
	 */
	public UserRemove(Activity activity, Account account)
			throws DBInterfaceError {
		super(activity, account);
	}

	@Override
	/**
	 * Do the task
	 * @param data - the account to remove
	 */
	protected boolean task(Account data) {
		boolean success = false;
		try {
			PreparedStatement removeAccount = conn
					.prepareStatement("DELETE FROM account WHERE accountName = ?");
			removeAccount.setString(1, data.getAccountName());
			removeAccount.execute();
			success = true;
		} catch (SQLException e) {
			success = false;
			e.printStackTrace();
		}

		return success;
	}
}